package com.mrzhou.auth.support;

import com.mrzhou.auth.constant.AuthConstant;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;

import java.util.HashMap;
import java.util.Map;

/**
 * 自定义密码解释工厂
 */
public class CloudPasswordEncoderFactory {

    private CloudPasswordEncoderFactory() { }

    public static PasswordEncoder createDelegatingPasswordEncoder() {
        Map<String, PasswordEncoder> encoders = new HashMap<>(5);
        encoders.put(AuthConstant.ENCRYPT_ID, new CloudPasswordEncoder());
        encoders.put("bcrypt", new BCryptPasswordEncoder());
        encoders.put(AuthConstant.CLIENT_ENCRYPT_ID, CloudNoPasswordEncoder.getInstance());
        encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
        encoders.put("scrypt", new SCryptPasswordEncoder());
        return new DelegatingPasswordEncoder(AuthConstant.ENCRYPT_ID, encoders);
    }

}
